package cc.wanforme.fsync.util;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class DateTimeTool {
    private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    private static final DateTimeFormatter dff = DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS);

    public static String format(long dateTime) {
        Instant instant = Instant.ofEpochMilli(dateTime);
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneOffset.systemDefault());
        return format(localDateTime);
    }
    public static String format(LocalDateTime dateTime) {
        return dff.format(dateTime);
    }

    public static DateTimeFormatter getFormatter(String pattern) {
        try {
            return DateTimeFormatter.ofPattern(pattern);
        } catch (Exception e) {
            return null;
        }
    }

}
